package com.eqdd.yiqidian.ui.discover.makerspace

import android.app.Activity
import android.content.Intent
import android.support.v7.widget.RecyclerView
import android.view.View
import com.eqdd.yiqidian.R
import com.eqdd.yiqidian.base.Config
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean
import com.eqdd.yiqidian.ui.SingleChooseActivity
import com.eqdd.yiqidian.ui.base.SlimBaseMultiEditActivity
import kotlinx.android.synthetic.main.activity_recyclerview.*
import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast

/**
 * Created by jhj on 18-8-3.
 */
class IndustryTypeActivity : SlimBaseMultiEditActivity() {


    private var industry: String? = null
    private var post: String? = null

    override fun initBinding() {
        clearData()
        setContentView(R.layout.activity_recyclerview)
        val title = intent.getStringExtra(Config.TITLE)
        val type = intent.getIntExtra(Config.TYPE, 0)
        initTopTitleBar(View.VISIBLE, title)
        initTopRightText("确定") {
            if (checkParams()) {
                val str = if (type == 1){
                    """{
                        "Industry":"$industry",
                        "post":"$post"
                    }"""
                }else{
                    """{
                        "industry":"$industry",
                        "post":"$post"
                    }"""
                }
                val intent = Intent()
                intent.putExtra("data", str)
                setResult(Activity.RESULT_OK, intent)
                finish()
            } else {
                toast(msg)
            }
        }

    }

    override fun initRecyclerView(): RecyclerView {
        return recyclerView
    }

    override fun itemClick(p: Int) {
        when (p) {
            0 -> startActivityForResult<SingleChooseActivity>(100, Config.TYPE to 2, Config.TITLE to "行业")
            1 -> startActivityForResult<SingleChooseActivity>(101, Config.TYPE to 1, Config.TITLE to "岗位")
        }
    }

    override fun setEditBeans() {
        datas.add(SlimEditEnterBean("行业", "", 0, "请选择").setNeed(true).setDeal(true))
        datas.add(SlimEditEnterBean("岗位", "", 1, "请选择").setNeed(true).setDeal(true))
    }


    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode == Activity.RESULT_OK) {
            val str = data?.getStringExtra("data")
            when (requestCode) {
                100 -> {
                    industry = str
                    slimAdapterEx?.getDataItem(0)?.content = str
                    slimAdapterEx?.notifyItemChanged(0)
                }
                101 -> {
                    post = str
                    slimAdapterEx?.getDataItem(1)?.content = str
                    slimAdapterEx?.notifyItemChanged(1)
                }
            }
        }
    }
}